//
//  HMStatusOriginalView.swift
//  Weibo
//
//  Created by 吴少飞 on 16/9/23.
//  Copyright © 2016年 wushaofei. All rights reserved.
//

import UIKit

class HMStatusOriginalView: UIView {

    
    var  statusesViewModel : HMStatusesViewModel?{
        didSet{
            
            nameLabel.text = statusesViewModel?.stuatus?.user?.screen_name
            
            if let urlName = statusesViewModel?.stuatus?.user?.profile_image_url {
   
                iconImageView.sd_setImage(with: URL(string: urlName), placeholderImage: UIImage(named: "avatar_default_big"))
               
                membershipImageView.image = statusesViewModel?.mbrankImage
                textLabel.text = statusesViewModel?.stuatus?.text
                createdLabel.text = statusesViewModel?.stuatus?.created_at
                sourceLabel.text = "新浪网"
            }
        }
    }
    //  MARK: --懒加载控件
    //用户头像
    private lazy var iconImageView:UIImageView = {
        
        let imageView = UIImageView()
        imageView.image = UIImage(named: "avatar_default_big")
        
        return imageView
    }()
    //用户认证
    private lazy var verifiedImageView:UIImageView = {
        
        
        let imageView = UIImageView()
        imageView.image = UIImage(named: "avatar_vip")
        return imageView
    }()
    
    //用户昵称
    private lazy var nameLabel:UILabel = UILabel(textFont: 13, textColor: UIColor.darkGray)
    //用户等级
    private lazy var membershipImageView:UIImageView = UIImageView(image: UIImage(named: "common_icon_membership"))
    //创建时间
    private lazy var createdLabel:UILabel = UILabel(textFont: 13, textColor: UIColor.orange)
    //来源
    private lazy var sourceLabel:UILabel = UILabel(textFont: 13, textColor: UIColor.darkGray)
    //内容
    private lazy var textLabel : UILabel = {
        let label = UILabel(textFont: 13, textColor: UIColor.darkGray)
        label.numberOfLines = 0
        return label
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    //  MARK: --搭建界面
    func setupUI(){
        
        addSubview(iconImageView)
        addSubview(verifiedImageView)
        addSubview(nameLabel)
        addSubview(membershipImageView)
        addSubview(createdLabel)
        addSubview(sourceLabel)
        addSubview(textLabel)
        
        //设置约束
        
        iconImageView.snp_makeConstraints { (make) in
            
            make.top.leading.equalTo(self).offset(HMStatusesCellMargin)
            make.size.equalTo(CGSize(width: 35, height: 35))
        }
        
        verifiedImageView.snp_makeConstraints { (make) in
            
            make.centerX.equalTo(iconImageView.snp_right)
            make.centerY.equalTo(iconImageView.snp_bottom)
        }
        
        nameLabel.snp_makeConstraints { (make) in
            
            make.top.equalTo(iconImageView)
            make.left.equalTo(iconImageView.snp_right).offset(HMStatusesCellMargin)
            
        }
        
        membershipImageView.snp_makeConstraints { (make) in
            
            make.left.equalTo(nameLabel.snp_right).offset(HMStatusesCellMargin)
            make.top.equalTo(nameLabel)
        }
        
        createdLabel.snp_makeConstraints { (make) in
            
            make.leading.equalTo(nameLabel)
            make.bottom.equalTo(iconImageView.snp_bottom)
        }
        
        sourceLabel.snp_makeConstraints { (make) in
            
            make.top.equalTo(createdLabel)
            make.left.equalTo(createdLabel.snp_right).offset(HMStatusesCellMargin)
        }
        
        textLabel.snp_makeConstraints { (make) in
            
            make.top.equalTo(iconImageView.snp_bottom).offset(HMStatusesCellMargin)
            make.left.equalTo(iconImageView)
            make.right.equalTo(self).offset(-HMStatusesCellMargin)
            make.bottom.equalTo(self).offset(HMStatusesCellMargin)
        }
        
        self.snp_makeConstraints { (make) in
            
            make.bottom.equalTo(textLabel.snp_bottom).offset(HMStatusesCellMargin)
        }
    }
}













